
#include "configboardoptions.h"
#include "ui_configboardoptions.h"
/*!
 * \brief ConfigBoardOptions::ConfigBoardOptions
 * \param parent
 */
ConfigBoardOptions::ConfigBoardOptions(QWidget *parent) :QMainWindow(parent),ui(new Ui::ConfigBoardOptions)
{
    ui->setupUi(this);
    plonk_type(0);
    ui->combobox_board->setCurrentIndex(0);

    ui->User_agent_selector->setCurrentIndex(0);
    //config *cnf_file =new config;
    //connect(this,SIGNAL(emit_fermeture()),cnf_file,SLOT(write_conf_board_init()));
    connect(ui->combobox_board,SIGNAL(activated(int)),this,SLOT(select_board(int)));
    connect(ui->combobox_board,SIGNAL(currentIndexChanged(int)),this,SLOT(select_board(int)));
    connect(ui->User_agent_selector,SIGNAL(activated(int)),this,SLOT(select_ua(int)));
    connect(ui->User_agent_selector,SIGNAL(currentIndexChanged(int)),this,SLOT(select_ua(int)));
    connect(ui->OK_configboard_pushButton,SIGNAL(clicked()),this,SLOT(click_ok_button_conf_validate()));
    connect(ui->lvl_plonk_spinbox,SIGNAL(valueChanged(int)),this,SLOT(plonk_type(int)));
    connect(ui->checkBox,SIGNAL(toggled(bool)),this,SLOT(order_posts_in_chrono(bool)));
    connect(ui->RefreshTime_spinBox,SIGNAL(valueChanged(int)),this,SLOT(set_timer_value(int)));
}

ConfigBoardOptions::~ConfigBoardOptions()
{
    delete ui;
}
void ConfigBoardOptions::build_uri(void)
{
    uri_get=add.append("/").append(xml_file_add);
    uri_post=add.append("/").append(post_path_file);
}
void ConfigBoardOptions::get_config_values()
{
    //Récupération de l'addresse
    /*set_add_conf();
    //Récupération du chemin du fichier
    set_xml_file_path();
    //Récupération du cookie
    set_cookie_value();
    //Récupération du chemin de post
    set_post_path();
    //Construction des requetes
    build_uri();*/
}

/*QString ConfigBoardOptions::access_add()
{
    return add;
}
QString ConfigBoardOptions::access_xml_path()
{
    return xml_file_add;
}
QString ConfigBoardOptions::access_post_path()
{
    return post_path_file;
}
QString ConfigBoardOptions::access_uri_get()
{
    return uri_get;
}
QString ConfigBoardOptions::access_uri_post()
{
    return uri_post;
}
QString ConfigBoardOptions::access_cookie()
{
    return cookie;
}*/
void ConfigBoardOptions::select_type(QString value)
{
    if(value=="Tribune Drupal")
    {
        type=1;
    }
    else
    {
        type=2;//ROR board
    }
}

void ConfigBoardOptions::set_add_conf(QString value)
{
    value=ui->Addr_edit->text();
    emit send_config_data_val_add(value);
}
void ConfigBoardOptions::set_xml_file_path(QString value)
{
    value=ui->TribuneXml_edit->text();
    emit send_config_data_val_xml_path(value);
}
void ConfigBoardOptions::set_cookie_value(QString value)
{
    //ui->cookie_field->textChanged(value);
    emit send_config_data_val_cookie(value);
}
void ConfigBoardOptions::set_post_path(QString value)
{
    value=ui->Post_url_field->text();
    emit send_config_data_val_post_url(value);
}
void ConfigBoardOptions::recoit_de_main_add(QString value)
{
    ui->Addr_edit->setText(value);
}
void ConfigBoardOptions::recoit_de_main_cookie(QString value)
{
    ui->cookie_field->setText(value);
}
void ConfigBoardOptions::recoit_de_main_post_url(QString value)
{
    ui->Post_url_field->setText(value);
}
void ConfigBoardOptions::recoit_de_main_ua(QString value)
{
    qDebug()<<value;
    ui->user_agent_label->setReadOnly(0);
    ui->user_agent_label->setText(value);
    ui->user_agent_label->setReadOnly(1);
}
void ConfigBoardOptions::recoit_de_main_xml_path(QString value)
{
    ui->TribuneXml_edit->setText(value);
}
void ConfigBoardOptions::recoit_de_main_tribune_post_type(QString type)
{
    ui->message_post_fl->setText(type);
}
void ConfigBoardOptions::plonk_type(int plonk_lvl)
{
    QString numero;
   qDebug()<<numero.setNum(plonk_lvl,10);
    if(plonk_lvl==0)
    {
        ui->desc_plonk->setText("Pas de plonkage activé");
        ui->lvlnum->setText("Pas de plonk");
    }
    else if(plonk_lvl==1)
    {
        ui->desc_plonk->setText("Cache les posts de l'utilisateur plonké");
        ui->lvlnum->setText("Low plonk profile");

    }
    else if(plonk_lvl==2)
    {

        ui->desc_plonk->setText("Cache les posts de l'utilisateur + les posts qui y répondent");
        ui->lvlnum->setText("High plonk level");
    }
    else
    {
        ui->desc_plonk->setText("Test de la fonction (n'apparait pas en éxecution normale)");
    }
}
void ConfigBoardOptions::recoit_de_main_user_name(QString value)
{
    ui->Post_name_field->setText(value);
}

void ConfigBoardOptions::click_ok_button_conf_validate()
{
    //Code d'appel de la fonction de récupération des parametres lors du click sur ok
    //get_config_values();
    //Réception de l'adresse (ex http://linuxfr.org)
    //ui->Addr_edit->setText(add);
    add=ui->Addr_edit->text();
    if(add.left(7)!="http://")
    {
        add="http://"+add;
    }
    emit send_config_data_val_add(add);
    //emit send_config_data_val_add_to_file(add);
    //Reception de l'addresse du fichier (ex board/index.xml)
    xml_file_add=ui->TribuneXml_edit->text();

    emit send_config_data_val_xml_path(xml_file_add);

    //qDebug()<<"Valeurs entree\n";
    cookie=ui->cookie_field->text();
    emit send_config_data_val_cookie(cookie);

    ua=ui->user_agent_label->text();
    emit send_config_data_val_user_agent(ua);
    post_path_file=ui->Post_url_field->text();
    emit send_config_data_val_post_url(post_path_file);

    type_board_string=ui->message_post_fl->text();
    emit send_type_board(type_board_string);

    user_name=ui->Post_name_field->text();
    emit send_user_name(user_name);
    reverse_order=ui->checkBox->checkState();
    emit send_reverse_post_checked(reverse_order);
    time=ui->RefreshTime_spinBox->value();
    emit send_time_value(time);
    qDebug()<<add;
    qDebug()<<cookie;
    qDebug()<<xml_file_add;
    qDebug()<<ua;
    qDebug()<<post_path_file;
    hide();
    emit emit_fermeture();
}
void ConfigBoardOptions::select_ua(int type)
{
    switch (type)
    {
    case 0:
        ui->user_agent_label->setReadOnly(true);
        ui->user_agent_label->setText("QtCoInCoIn");
        break;
    case 1:
        ui->user_agent_label->setReadOnly(true);
        ui->user_agent_label->setText("Mozilla/5.0 (X11; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0");
        break;
    case 2:
        ui->user_agent_label->setReadOnly(true);
        ui->user_agent_label->setText("wmCoinCoin 2.6.1");
        break;
    case 3:
        ui->user_agent_label->setReadOnly(true);
        ui->user_agent_label->setText("quteqoin crash edition");
        break;
    case 4:
        ui->user_agent_label->setReadOnly(true);
        ui->user_agent_label->setText("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; Trident/5.0)");
        break;
    case 5:
        ui->user_agent_label->setReadOnly(false);
    default:
        ui->user_agent_label->setReadOnly(false);
        break;
    }
}
void ConfigBoardOptions::select_board(int board)
{
    switch(board)
    {
    case 0:
        ui->Addr_edit->setReadOnly(false);
        ui->TribuneXml_edit->setReadOnly(false);
        ui->Post_url_field->setReadOnly(false);
        ui->message_post_fl->setReadOnly(false);
        break;
    case 1:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://linuxfr.org");
        ui->TribuneXml_edit->setText("board/index.xml");
        ui->Post_url_field->setText("board");
        ui->message_post_fl->setText("board[message]=");
        break;
    case 2:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://euromussels.eu");
        ui->TribuneXml_edit->setText("tribune.xml");
        ui->Post_url_field->setText("tribune/post");
        ui->message_post_fl->setText("message=");
        break;
    case 3:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://batavie.leguyader.eu");
        ui->TribuneXml_edit->setText("remote.xml");
        ui->Post_url_field->setText("index.php/add");
        ui->message_post_fl->setText("message=");
        break;
        /**
          *@info dax.sveetch.net is dead , now switching to www.sveetch.net
          *@since 0.3.1
          */
    case 4:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://www.sveetch.net");
        ui->TribuneXml_edit->setText("tribune/remote.xml");
        ui->Post_url_field->setText("tribune/post.xml");
        ui->message_post_fl->setText("content=");
        break;
    case 5:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://hadoken.free.fr");
        ui->TribuneXml_edit->setText("board/remote.php");
        ui->Post_url_field->setText("board/post.php");
        ui->message_post_fl->setText("message=");
        break;
    case 6:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://www.finss.fr");
        ui->TribuneXml_edit->setText("drupal/tribune/xml");
        ui->Post_url_field->setText("drupal/tribune/post");
        ui->message_post_fl->setText("message=");
        break;
    case 7:
        ui->Addr_edit->setReadOnly(true);
        ui->TribuneXml_edit->setReadOnly(true);
        ui->Post_url_field->setReadOnly(true);
        ui->message_post_fl->setReadOnly(true);
        ui->Addr_edit->setText("http://ygllo.com");
        ui->TribuneXml_edit->setText("tribune.xml");
        ui->Post_url_field->setText("tribune/post");
        ui->message_post_fl->setText("message=");
        break;

    default:
        ui->Addr_edit->setReadOnly(false);
        ui->TribuneXml_edit->setReadOnly(false);
        ui->Post_url_field->setReadOnly(false);
        ui->message_post_fl->setReadOnly(false);
        break;

    }
}
void ConfigBoardOptions::recoit_de_main_ua_value(int value)
{
    select_ua(value);
}
void ConfigBoardOptions::order_posts_in_chrono(bool value)
{
    emit send_reverse_post_checked(value);
}
void ConfigBoardOptions::recoit_de_main_bool_set(bool val)
{
    ui->checkBox->setChecked(val);
}
void ConfigBoardOptions::set_timer_value(int value)
{
    time=value;
}
void ConfigBoardOptions::recoit_de_main_time(int temps)
{
    ui->RefreshTime_spinBox->setValue(temps);
}
